package com.example.spring_aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_yizYa
 * Date: 2025/7/23
 * Time: 17:53
 */
@Slf4j
//@Component
@Aspect
public class AspectDemo {

    @Pointcut("execution(* com.example.spring_aop.controller.*.*(..))")
    public void pt() {

    }
    @Before("pt()")
    public void doBefore() {
        log.info("AspectDemo 执行doBefore...");
    }

    @After("pt()")
    public void doAfter() {
        log.info("AspectDemo 执行doAfter...");
    }

    @AfterReturning("pt()")
    public void doAfterReturning() {
        log.info("AspectDemo 执行doAfterReturning...");
    }

    @AfterThrowing("pt()")
    public void doAfterThrowing() {
        log.info("AspectDemo 执行doAfterThrowing...");
    }

    @Around("pt()")
    public Object doAround(ProceedingJoinPoint pjt) {
        log.info("around 前处理");
        Object o = null;
        try {
            o = pjt.proceed();
        } catch (Throwable e) {
            log.info("around 发生异常...");
        }
        log.info("around 后处理");
        return o;
    }
}
